package cpr.data;

import cpr.Rule;
import cpr.Utils;
import cpr.helper.ScoreHelper;

public class HLVector implements Comparable {
	public int[] values = new int[Rule.HLIS.length];
    public int score = 0;
    
    public HLVector(int score) {
    	this.values = Utils.decayScore(score,Rule.HL_SCORE);
        this.score = Utils.getScore(values);
        if (this.score!=score) {
        	throw new RuntimeException("hl vector problem");
        }
    }
	
    public HLVector(int[] values) {
        this.values = values;
        this.score = Utils.getScore(values);
    }
	
    public HLVector(HLVector copyFrom) {
        copyFrom(copyFrom);
    }
    public String toString() {
    	return ScoreHelper.printHLVectorAsArray(this);
    }
    
	public boolean equals(Object obj) {
    	HLVector other = (HLVector)obj;
    	for (int i = 0; i < other.values.length; i++) {
			if (values[i]!=other.values[i]) return false;
		}
		return true;
	}

	public boolean comparable(HLVector o) {
		HLVector other = (HLVector)o;
		if (score==other.score) return true;
		int p = 0;
		int m = 0;
		for (int i = 0; i < other.values.length; i++) {
			if (values[i]>other.values[i]) {
				p++;
			} else if (values[i]<other.values[i]) {
				m++;
			}
		}
		if ((p>0)&&(m>0)) return false;
		return true;
	}
	public int compareTo(Object o) {
		HLVector other = (HLVector)o;
		if (score==other.score) return 0;
		int p = 0;
		int m = 0;
		for (int i = 0; i < other.values.length; i++) {
			if (values[i]>other.values[i]) {
				p++;
			} else if (values[i]<other.values[i]) {
				m++;
			}
		}
		if ((p>0)&&(m==0)) return 1;
		if ((m>0)&&(p==0)) return -1;
		return 0;
	}
	
	
    
    public int getValue(int hlindex) {
        return values[hlindex];
    }
    public int getScore() { return score;}
    public void copyFrom(HLVector copyFrom) {
        this.values = copyFrom.values;
        this.score = copyFrom.score;
    }
}
